package com.zyb.beiojbackendjudgeservice.codesandbox;


import com.zyb.beiojbackendjudgeservice.codesandbox.impl.ExampleCodeSandbox;
import com.zyb.beiojbackendjudgeservice.codesandbox.impl.RemoteCodeSandbox;
import com.zyb.beiojbackendjudgeservice.codesandbox.impl.ThirdPartyCodeSandbox;
import com.zyb.beiojcommon.common.ErrorCode;
import com.zyb.beiojcommon.exception.BusinessException;
import com.zyb.beiojmodel.model.enums.CodeSandboxTypeEnum;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author 十八岁讨厌编程
 * @date 2025/2/8 10:04
 * @PROJECT_NAME beioj-backend
 * @description
 */

@Component
public class CodeSandboxFactory implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public CodeSandbox selectCodeSandbox(CodeSandboxTypeEnum type){

        switch (type) {
            case EXAMPLE:
                return applicationContext.getBean(ExampleCodeSandbox.class);
            case THIRD_PARTY:
                return applicationContext.getBean(ThirdPartyCodeSandbox.class);
            case REMOTE:
                return applicationContext.getBean(RemoteCodeSandbox.class);
            default:
                throw new BusinessException(ErrorCode.PARAMS_ERROR,"不存在该类型沙箱");
        }
    }

}
